<?php
require('../vendor/autoload.php');

use BitWasp\Bitcoin\Mnemonic\MnemonicFactory;
use BitWasp\Bitcoin\Key\Deterministic\HierarchicalKeyFactory;
use BitWasp\Bitcoin\Network\NetworkFactory;

$network = NetworkFactory::bitcoinRegtest();

$mnemonic = file_get_contents('./wallet/mnemonic');
$bip39 = MnemonicFactory::bip39();
$entropy = $bip39->mnemonicToEntropy($mnemonic);
$masterKey = HierarchicalKeyFactory::fromEntropy($entropy);

$xprv = $masterKey->toExtendedPrivateKey($network);
echo 'xprv => ' . $xprv . PHP_EOL;
$xpub = $masterKey->toExtendedPublicKey($network);
echo 'xpub => ' . $xpub . PHP_EOL;

file_put_contents('./wallet/master-xprv',$xprv);
file_put_contents('./wallet/master-xpub',$xpub);